const fs = require('fs') 
function streamToFile(stream, saveFilePath) {
    return new Promise((res, rej) => {
      const ws = fs.createWriteStream(saveFilePath);
      stream.pipe(ws).on('finish', () => {
        console.log(`========= ${saveFilePath} pipe finish =========`);
        res(saveFilePath);
      });
      ws.on('error', err => {
        console.log(`========= ${saveFilePath} pipe error =========`);
        rej(err);
      });
    });
  }
  module.exports = streamToFile